﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Utils;
using Utils.DatabaseUtils;

namespace DCSLibrary
{
    public class RoleUI
    {
        public DataSet GetAll()
        {
            try
            {
                return SqlHelper.ExecuteDataset(Common.Conn, CommandType.StoredProcedure, "Role_getall");
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }

        public DataSet GetByID(int RoleID)
        {
            try
            {
                return SqlHelper.ExecuteDataset(Common.Conn, "Role_get", RoleID);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }

        public int DeleteByID(int RoleID)
        {
            try
            {
                return SqlHelper.ExecuteNonQuery(Common.Conn, "Role_delete", RoleID);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }

        public int Add(String RoleName, int ParentID, String Description, byte IsSuperAdmin)
        {
            try
            {
                return SqlHelper.ExecuteNonQuery(Common.Conn, "Role_add", RoleName, ParentID, Description, IsSuperAdmin);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }

        public int Add(String RoleName, int? ParentID, String Description, byte IsSuperAdmin, string pageList)
        {
            try
            {
                return SqlHelper.ExecuteNonQuery(Common.Conn, "Role_addwithpagerole", RoleName, ParentID, Description, IsSuperAdmin, pageList);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }

        public int Update(int RoleID, String RoleName, int ParentID, String Description, byte IsSuperAdmin)
        {
            try
            {
                return SqlHelper.ExecuteNonQuery(Common.Conn, "Role_update", RoleID, RoleName, ParentID, Description, IsSuperAdmin);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }

        public int Update(int RoleID, String RoleName, int? ParentID, String Description, byte IsSuperAdmin, string PageList)
        {
            try
            {
                return SqlHelper.ExecuteNonQuery(Common.Conn, "Role_updatewithpagerole", RoleID, RoleName, ParentID, Description, IsSuperAdmin, PageList);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }
    }
}
